/**
 * 
 */
package cn.simonfish.acus.examples.controllers;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.json.annotations.JSON;
import org.springframework.stereotype.Controller;

import cn.simonfish.acus.common.data.DataSet;
import cn.simonfish.acus.common.model.JSONMessage;

import com.alibaba.fastjson.JSONObject;
import com.sinoservices.xframework.core.security.UserContext;
import com.sinoservices.xframework.core.support.controllers.ActionSupport;

/**
 * @author Simon Yu
 *
 */
@Controller
public class SimplePageAction extends ActionSupport {
	
	private String userName;
	
	private Map map;
	
	private JSONMessage json;
	
	private DataSet dataSet;
	
	public String saveRow(){
		json = new JSONMessage();
		json.setSuccess(true);
		json.setData(new HashMap());
//		return "xson";
		return SUCCESS;
	}
	
	/**
	 * @return
	 */
	public String loadData(){
//		UserContext user =null;
//		user.isDeptAdmin();
//		
//		user.isRole("DEPT_AMDIN");
//		user.isRole("Cilc_");
//		user.isRole("DEPT_AMDIN");
//		user.isRole("DEPT_AMDIN");
		new JSONObject();
//		com.alibaba.fastjson.JSON.parseObject("").
		
		map = new HashMap();
		map.put("userCode", 1001221);
		map.put("userName", "Simon");
		map.put("aliasName", "Fish");
		map.put("address", "FJ XM");
		map.put("endTime", new Date(2011-1900,10,13));
		map.put("startTime", new Date(2011-1900,1,4));
		map.put("birthday", new Date());
		
		json = new JSONMessage();
		json.setSuccess(true);
		json.setData(map);
		return "xson";
	}
	
	
	public String loadGridData(){
		dataSet = new DataSet();
		dataSet.setTotal(123);
		for (int i = 0; i < 20; i++) {
			Map row = new HashMap();
			row.put("userCode", "100"+i);
			row.put("userName", "姓名"+i);
			row.put("aliasName", "alias-"+i);
			row.put("address", "address"+i);
			row.put("startTime", new Date(2011-1900,1,4));
			row.put("endTime", new Date());
			row.put("birthday", new Date());
			
			dataSet.addRow(row);
		}
		
		return "xson";
	}

	/**
	 * @return the userName
	 */
	public String getUserName() {
		return userName;
	}

	/**
	 * @param userName the userName to set
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}

	/**
	 * @return the map
	 */
	public Map getMap() {
		return map;
	}

	/**
	 * @param map the map to set
	 */
	public void setMap(Map map) {
		this.map = map;
	}

	/**
	 * @return the json
	 */
	@JSON(format="yyyy-MM-dd")
	public JSONMessage getJson() {
		return json;
	}

	/**
	 * @param json the json to set
	 */
	public void setJson(JSONMessage json) {
		this.json = json;
	}


	/**
	 * @return the dataSet
	 */
	public DataSet getDataSet() {
		return dataSet;
	}


	/**
	 * @param dataSet the dataSet to set
	 */
	public void setDataSet(DataSet dataSet) {
		this.dataSet = dataSet;
	}
	
	

}
